package com.ruoyi.fangyuan.aop;

import com.ruoyi.fangyuan.config.DBContextHolder;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

/**
 * @Title: DataSourceAop
 * @Description:
 * @Auther: 龙天
 * @Version: 1.0
 * @create 2023/5/5 15:12
 */
@Aspect
@Component
public class DataSourceAop {
    @Pointcut("@annotation(com.ruoyi.fangyuan.config.Slave)")
    public void readPointcut () {}

    /**
     * 读取时切换分支
     */
    @Before("readPointcut()")
    public void read () {
        DBContextHolder.slave();
    }

    @Pointcut("@annotation(com.ruoyi.fangyuan.config.Master)")
    public  void writePointcut () {}

    @Before("writePointcut()")
    public void write () {
        DBContextHolder.master();
    }
}
